package SortAlgotithm;

/**
 * Created by root on 17-3-7.
 */
public class QuickSort {
    // {49 , 38 , 65 , 97 , 13 , 27 , 50}
    public void QuickSort(int [] list , int start , int end ) {
        if (start >= end) {
            return;
        }
        int position = findPosition(list , start , end);
        QuickSort(list , start , position - 1);
        QuickSort(list , position + 1 , end);
    }

    public int findPosition(int [] list , int start , int end) {
        int key = list[start];
        while (start < end) {
            while (start < end && list[end] >= key )
                end --;
            list[start] = list[end];
            while(start < end && list[start] <= key )
                start ++;
            list[end] = list[start];
        }
        list[start] = key;
        return start;
    }
    public void swap(int [] c , int  s1, int s2) {
        int temp = c[s1];
        c[s1] = c[s2];
        c[s2] = temp;
    }
}
